﻿using System;
using System.Media;
using System.Net;
using System.Windows.Forms;
using RawSocketDll;

namespace WeaponEvalue
{
    public partial class FormAbout : Form
    {
        private RawSocket myRawSock;
        private bool stop = false;

        public FormAbout()
        {
            InitializeComponent();
        }
        private readonly SoundPlayer player = new SoundPlayer();

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (stop)
            {
                player.Play();
            }
            stop = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var hosyEntry = Dns.GetHostEntry(Dns.GetHostName());

            if (hosyEntry.AddressList.Length > 0)
            {
                myRawSock = new RawSocket(hosyEntry.AddressList[0]);
                myRawSock.PacketArrival += DataArrival;
                myRawSock.KeepRunning = true;
                myRawSock.Run();
            }

            player.SoundLocation = string.Format("{0}\\{1}", Application.StartupPath, "alert.wav");
            player.LoadAsync();
            timer1.Enabled = true;
        }

        private void DataArrival(object sender, RawSocket.PacketArrivedEventArgs args)
        {
            if ("TCP".Equals(args.Protocol, StringComparison.CurrentCultureIgnoreCase))
            {
                if (textBox1.Text.Equals(args.OriginationPort))
                {
                    stop = false;
                }
            }
        }
    }
}